﻿@using System.Globalization
@model Project.Domain.Entities.Match
@{   
    var controller = ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString();
    ViewBag.Title = "Modify" + controller.ToString(CultureInfo.InvariantCulture);
    var id = Convert.ToInt32(ViewBag.Id);
    var timePlay = "";
    var startTime = string.Format("{0:dd/MM/yyyy}", DateTime.Now);
    if(Model!=null)
    {
        timePlay = Model.TimePlay;
        startTime = string.Format("{0:dd/MM/yyyy}", Model.StartTime);
    }
}

@{
    ViewBag.Title = "Modify" + controller.ToString();
}
<script type="text/javascript">
    $(document).ready(function() {
        $('#date').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'dd/mm/yy',
            yearRange: '2011:2050'
        });
    });
    function save() {
        var options = {
            beforeSubmit: showRequest,  // pre-submit callback 
            success: showResponse  // post-submit callback 
        };
        $('#date').val();
        $('#time').val();
        $('#frmManagement').ajaxSubmit(options);
    }

    function showRequest(formData, jqForm, options) {
        var form = jqForm[0];        
        if (form.date.value == '') {
            alert('Vui lòng điền đầy đủ thông tin.');
            return false;
        }
        if (form.time.value == '') {
            alert('Vui lòng điền đầy đủ thông tin.');
            return false;
        }
    }

    function showResponse(responseText, statusText, xhr, $form) {
        if (responseText == '1') {
            var url = root + "Admin/" + "@controller.ToString()" + "/#/save";
            location.href = url;
        }
        if(responseText=='2') {
            alert("Match is InPlay! You can not edit");
            var url = root + "Admin/" + "@controller.ToString()" + "/#/inplay";
            location.href = url;
        }
        if(responseText=='3') {
            alert("Match is Closed! You can not edit");
            var url = root + "Admin/" + "@controller.ToString()" + "/#/closed";
            location.href = url;
        }
    }
</script>
<div class="table">
    <div class="head_table">
        <div class="head_title_edit">@controller</div>
    </div>
	<div class="clearAll"></div>
	@using (Html.BeginForm("Modify", "Match", FormMethod.Post, new { id = "frmManagement" }))
    {
        <input type="hidden" value="@ViewBag.Id" name="hiddenIdAdmincp" />
        <div class="row_text_field_first">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
                <tr>
                    <td class="left_text_field">Status:</td>
                    <td class="right_text_field">                                                
                        <input type="checkbox" class="custom_chk" name="statusAdmincp" />                                               
                    </td>
                </tr>
            </table>
        </div>

        <div class="row_text_field">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
                <tr>
                    <td class="left_text_field">League Name:</td>
                    <td class="right_text_field">
                        @Html.DropDownList("leagueId", ViewBag.league as SelectList, new {style = "width:213px;height:24px; text-align:center;padding-top:2px;"})
                    </td>
                </tr> 
            </table>
        </div>

        <div class="row_text_field">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
                <tr>
                    <td class="left_text_field">Date:</td>
                    <td class="right_text_field">
                        <input type="text" name="date" value="@startTime" id="date" style="width: 200px;"/>
                 </td>                 
             </tr> 
         </table>
     </div>    
     <div class="row_text_field">
         <table cellspacing="0" cellpadding="0" border="0" width="100%">
             <tr>                 
                 <td class="left_text_field">Time:</td>
                 <td class="right_text_field">
                     <input type="text" name="time" id="time" value="@timePlay" style="width: 200px;"/>
                 </td>
             </tr> 
         </table>
     </div>     
   

     <div class="row_text_field">
         <table cellspacing="0" cellpadding="0" border="0" width="100%">                                               
             <tr>
                 <td class="left_text_field" style="vert-align:middle">HomeTeam Name:</td>
                 <td class="right_text_field">
                     @Html.DropDownList("homeId", ViewBag.homeTeam as SelectList, new { style = "width:213px;height:24px; text-align:center;padding-top:2px;" })
                 </td>
                 <td class="left_text_field">AwayTeam Name:</td>
                 <td class="right_text_field">
                     @Html.DropDownList("awayId", ViewBag.awayTeam as SelectList, new { style = "width:213px;height:24px; text-align:center;padding-top:2px;" })
                 </td>

             </tr>
         </table>
     </div>            
 }
</div>